package com.ithinkstudio.jeez.service.impl;

import com.ithinkstudio.jeez.dao.IUserRepository;
import com.ithinkstudio.jeez.entity.User;
import com.ithinkstudio.jeez.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: springboot-mybatis
 * @description: 用户服务层
 * @author: fengzp
 * @create: 2020/04/14
 */
@Service
public class UserService implements IUserService {

    @Resource
    private IUserRepository userRepository;

    /**
     * 根据ID查询用户
     *
     * @param id
     * @return
     */
    @Override
    public User findById(Integer id) {
        return userRepository.findById(id).get();
    }

    /**
     * 新增用户
     *
     * @param user
     */
    @Override
    public void insertUser(User user) {
        userRepository.save(user);
    }

    /**
     * 更新用户
     *
     * @param user
     */
    @Override
    public void updateUser(User user) {
        userRepository.save(user);
    }

    /**
     * 删除用户
     *
     * @param id
     */
    @Override
    public void deleteUser(Integer id) {
        userRepository.deleteById(id);
    }
}
